import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 创建应用实例
const app = createApp(App)
const pinia = createPinia()

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 先使用pinia以便能够访问store
app.use(pinia)

// 初始化用户状态 - 在挂载应用和使用router之前
import { useUserStore } from './store/user'
const userStore = useUserStore()
userStore.initUserState()

// 然后再使用router和ElementPlus
app.use(router)
app.use(ElementPlus)

// 最后挂载应用
app.mount('#app')